package promote.brozen.base.thread;

import promote.brozen.utils.concurrent.Threads;

import java.util.concurrent.locks.LockSupport;

/**
 * @author Brozen
 * @date 2020/9/10 5:18 PM
 * @email brozen@qq.com
 */
public class BlockInterrupt {

    private static final Object MONITOR = new Object();

    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            System.out.println("T1 start");
            Threads.silentSleep(1000L);
            synchronized (MONITOR) {
                System.out.println("T1 get lock, interrupted=" + Thread.currentThread().isInterrupted());
            }
        });

        Thread t2 = new Thread(() -> {
            synchronized (MONITOR) {
                System.out.println("T2 get lock, T1=" + t1.getState());

                t1.interrupt();
                System.out.println("T1 interrupted=" + t1.isInterrupted() + " state=" + t1.getState());

                Threads.silentSleep(2000L);
                System.out.println("T2 get up, T1=" + t1.getState());

                // t1.interrupt();
                // System.out.println("T1 interrupted=" + t1.isInterrupted());
            }
        });

        t1.start();
        t2.start();

        LockSupport.park();
    }

}
